package com.boot.unity.api.modules.schedule;

import com.boot.unity.api.modules.listener.StudentSyncService;
import com.boot.unity.api.modules.train.dao.StudentDao;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author X
 * @create 2020-10-29 14:45
 */
@Component
@AllArgsConstructor
public class SyncSchedule {
    private final StudentDao studentDao;
    private final StudentSyncService studentSyncService;
    /**
     * 10分钟推送一次
     * 2分钟推送一次
     */
//    @Scheduled(fixedRate = 2*60*1000)
    //@PostConstruct
//    @Async("studentSyncTaskExecutor")
    public void studentSyncSchedule(){
        List<String> cardNoList = studentDao.listCardNo4Sync();
        // 测试使用
        //List<String> cardNoList = studentDao.list4Test();
        if (CollectionUtils.isNotEmpty(cardNoList)){
            cardNoList.forEach(cardNo -> studentSyncService.studentSync(cardNo));
        }
    }

}
